//
//  UIScrollView+Tab.swift
//  TestSwift
//
//  Created by Mac on 2021/12/24.
//  Copyright © 2021 Song. All rights reserved.
//

import UIKit

extension UIScrollView {
    /// 监听tabScrollView的滚动方向
    func qs_addObserverToTabScrollDirection() {
        let notName = Notification.Name(rawValue: kTabScrollViewScrollDirection)
        NotificationCenter.default.addObserver(self,
                                               selector: #selector(self.tabScrollViewScrollDirection(not:)),
                                               name: notName, object: nil)
    }
    
    /// 左右滑动和上下滑动不能同时响应
    @objc private func tabScrollViewScrollDirection(not: Notification) {
        if let direction = not.userInfo?["direction"] as? QSScrollDirection {
            if direction == .horizontal || direction == .left || direction == .right {
                self.isScrollEnabled = false
            } else {
                self.isScrollEnabled = true
            }
        }
    }
}
